Markus Spoetti adds lap splitting to Garmin Training Center.
authorrobertl <robertl>
Thu, 7 Aug 2008 02:10:29 +0000 (02:10 +0000)
committerrobertl <robertl>
Thu, 7 Aug 2008 02:10:29 +0000 (02:10 +0000)
defs.h
garmin.c
gtrnctr.c

diff --git a/defs.h b/defs.h
index 92e5e6dbe079fb92822b2a8e9c8e6c9bbc733768..6f8ad4536d6c8d627cce20a40d991a1b29221773 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -335,6 +335,8 @@ typedef struct {
        unsigned int altitude:1;                /+ altitude field is set +/
        ... and others
        */
+       unsigned int is_split:1;                /* the waypoint represents a split */
+
        
 } wp_flags;
 
index 1336ec18f62ad17aa0be4e797e534f06eec1f4d2..db800c072886bc558568eb2282d5e97d21415527 100644 (file)
--- a/garmin.c
+++ b/garmin.c
@@ -352,6 +352,40 @@ waypt_read(void)
        }
 }
 
+static int lap_read_nop_cb(int n, struct GPS_SWay** dp)
+{
+       return 0;
+}
+
+// returns 1 if the waypoint's start_time can be found
+// in the laps array, 0 otherwise
+unsigned int checkWayPointIsAtSplit(waypoint *wpt, GPS_PLap *laps, int nlaps)
+{
+    int result = 0;
+
+    if ((laps != NULL) && (nlaps > 0)) {
+        int i;
+        for (i=(nlaps-1); i >= 0; i--) {
+            GPS_PLap lap = laps[i];
+            time_t delta = lap->start_time - wpt->creation_time;
+            if ((delta >= -1) && (delta <= 1)) {
+                result = 1;
+                break;
+
+            // as an optimization this will stop going through
+            // the lap array when the negative delta gets too
+            // big. It assumes that laps is sorted by time in
+            // ascending order (which appears to be the case for
+            // Forerunners. Don't know about other devices.
+            } else if (delta < -1) {
+                break;
+            }
+        }
+    }
+
+   return result;
+}
+
 static
 void
 track_read(void)
@@ -364,6 +398,13 @@ track_read(void)
        int trk_seg_num = 1;
        char trk_seg_num_buf[10];
        char *trk_name = "";
+       GPS_PLap* laps = NULL;
+       int nlaps = 0;
+
+       if (gps_lap_type != -1) {
+               nlaps = GPS_Command_Get_Lap(portname, &laps, &lap_read_nop_cb);
+       }
+
 
        ntracks = GPS_Command_Get_Track(portname, &array, waypt_read_cb);
 
@@ -414,6 +455,8 @@ track_read(void)
                wpt->cadence = array[i]->cadence;
                wpt->shortname = xstrdup(array[i]->trk_ident);
                wpt->creation_time = array[i]->Time;
+                wpt->wpt_flags.is_split = checkWayPointIsAtSplit(wpt, laps,
+                                                                 nlaps);
                
                track_add_wpt(trk_head, wpt);
        }
index 12446e91b9ed51701c466a300c79c81ba19034a7..296f6bef254e41b212dabf9c7f649e125e99656a 100644 (file)
--- a/gtrnctr.c
+++ b/gtrnctr.c
@@ -120,7 +120,12 @@ gtc_waypt_pr(const waypoint *wpt)
        xml_write_time(ofd, wpt->creation_time, "Time");
        gbfprintf(ofd, "            </Trackpoint>\n");
 #else
-       gtc_write_xml(1, "<Trackpoint>\n");
+    if (wpt->wpt_flags.is_split != 0) {
+        gtc_write_xml(1, "<Trackpoint split=\"yes\">\n");
+    } else {
+        gtc_write_xml(1, "<Trackpoint>\n");
+    }
+
        if (wpt->creation_time) {
                char time_string[100];
                xml_fill_in_time(time_string, wpt->creation_time, wpt->microseconds,